<template>
  <div v-loading="loading" class="parentStyle">
    <div class="area-header">
      <span class="area-header-title">{{ $t('其他信息') }}</span>
    </div>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="24">
          <el-form-item :label="$t('上市情况')" prop="listingSituation">
            <el-input v-model="form.listingSituation" type="textarea" :placeholder="$t('上市情况')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('企业荣誉')" prop="corporateHonors">
            <el-input v-model="form.corporateHonors" type="textarea" :placeholder="$t('企业荣誉')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('是否新三板企业')">
            <el-radio-group v-model="form.isNewThirdBoardEnterprises">
              <el-radio
                v-for="dict in isNewThirdBoardEnterprisesOptions"
                :key="dict.dictValue"
                :label="dict.dictValue"
              >{{ dict.dictLabel }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col v-if="form.isNewThirdBoardEnterprises === 'Y'" :span="12">
          <el-form-item :label="$t('新三板代码')" prop="newThirdBoardCode">
            <el-input v-model="form.newThirdBoardCode" :placeholder="$t('新三板代码')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('是否属于中小企业')">
            <el-radio-group v-model="form.isMinorEnterprises">
              <el-radio
                v-for="dict in isMinorEnterprisesOptions"
                :key="dict.dictValue"
                :label="dict.dictValue"
              >{{ dict.dictLabel }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('是否属于独角兽企业')">
            <el-radio-group v-model="form.isUnicornEnterprise">
              <el-radio
                v-for="dict in isUnicornEnterpriseOptions"
                :key="dict.dictValue"
                :label="dict.dictValue"
              >{{ dict.dictLabel }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('是否属于瞪羚企业')">
            <el-radio-group v-model="form.isGazelleEnterprise">
              <el-radio
                v-for="dict in isGazelleEnterpriseOptions"
                :key="dict.dictValue"
                :label="dict.dictValue"
              >{{ dict.dictLabel }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('是否属于创新型企业')">
            <el-radio-group v-model="form.isInnovativeEnterprises">
              <el-radio
                v-for="dict in isInnovativeEnterprisesOptions"
                :key="dict.dictValue"
                :label="dict.dictValue"
              >{{ dict.dictLabel }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('存续期限')" prop="duration">
            <el-input v-model="form.duration" :placeholder="$t('存续期限')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('实际经营地')" prop="actualBusinessLocation">
            <el-input v-model="form.actualBusinessLocation" :placeholder="$t('实际经营地')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('其他亮点')" prop="otherHighlights">
            <el-input v-model="form.otherHighlights" type="textarea" :placeholder="$t('其他亮点')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('退出方式')" prop="exitPattern">
            <dict-select
              v-model="form.exitPattern"
              dictionary="bf_invest_exit_pattern"
              :placeholder="$t('退出方式')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('委派董监高情况')" prop="delegationSituation">
            <el-input v-model="form.delegationSituation" :placeholder="$t('委派董监高情况')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('是否是管理公司')">
            <el-radio-group v-model="form.isManagementCompany">
              <el-radio
                v-for="dict in isManagementCompanyOptions"
                :key="dict.dictValue"
                :label="dict.dictValue"
              >{{ dict.dictLabel }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col v-if="form.isManagementCompany === 'Y'" :span="12">
          <el-form-item :label="$t('组织形式')" prop="organizationalForm">
            <dict-select
              v-model="form.organizationalForm"
              dictionary="organizational_form"
              :placeholder="$t('组织形式')"
            />
          </el-form-item>
        </el-col>
        <el-col v-if="form.isManagementCompany === 'Y'" :span="12">
          <el-form-item :label="$t('参与方式')" prop="participationMethod">
            <dict-select
              v-model="form.participationMethod"
              dictionary="participation_method"
              :placeholder="$t('参与方式')"
            />
          </el-form-item>
        </el-col>
        <el-col v-if="form.isManagementCompany === 'Y'" :span="12">
          <el-form-item :label="$t('发起人')" prop="promoter">
            <el-input v-model="form.promoter" :placeholder="$t('发起人')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col v-if="form.isManagementCompany === 'Y'" :span="12">
          <el-form-item :label="$t('GP团队核心人士')" prop="gpTeamCoreMembers">
            <el-input v-model="form.gpTeamCoreMembers" :placeholder="$t('GP团队核心人士')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存 取消按钮-->
      <save-btn has-permi="other:info" :cancel-show="false" />
    </div>
  </div>
</template>

<script>
import {
  saveDfgzDealOtherInfo,
  getDfgzDealOtherInfoByMainId
} from '@/api/sass/dfgz/dfgzDealOtherInfo'
import { getCompanyBase } from '@/api/company/base/companyBase'
export default {
  data() {
    return {
      // 表单参数
      form: {},
      // 主表ID
      mainId: this.$route.query.dealId ? this.$route.query.companyId : this.$route.query.id,
      // 是否新三板企业
      isNewThirdBoardEnterprisesOptions: [],
      // 是否属于中小企业
      isMinorEnterprisesOptions: [],
      // 是否属于独角兽企业
      isUnicornEnterpriseOptions: [],
      // 是否属于瞪羚企业
      isGazelleEnterpriseOptions: [],
      // 是否属于创新型企业
      isInnovativeEnterprisesOptions: [],
      // 是否属于管理公司
      isManagementCompanyOptions: [],
      // 遮罩层
      loading: false,
      // 表单校验
      rules: {
        newThirdBoardCode: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        isManagementCompany: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.init()
    this.getDicts('sys_yes_no').then(response => {
      this.isNewThirdBoardEnterprisesOptions = response.data
      this.isMinorEnterprisesOptions = response.data
      this.isUnicornEnterpriseOptions = response.data
      this.isGazelleEnterpriseOptions = response.data
      this.isInnovativeEnterprisesOptions = response.data
      this.isManagementCompanyOptions = response.data
    })
    this.getDicts('bf_invest_exit_pattern').then(response => {
      this.exitPatternOptions = response.data
    })

    this.getDicts('organizational_form').then(response => {
      this.organizationalFormOptions = response.data
    })
    this.getDicts('participation_method').then(response => {
      this.participationMethodOptions = response.data
    })
  },
  methods: {
    // 初始化数据
    init(data) {
      this.loading = true
      if (data != null && data.id !== undefined) {
        getDfgzDealOtherInfoByMainId(data.id).then(response => {
          if (response.data) {
            this.form = response.data
          } else {
            this.reset()
            if (this.$route.query.companyId) {
              getCompanyBase(this.$route.query.companyId).then(res => {
                if (res.data) {
                  this.form.actualBusinessLocation = res.data.detailsRegistered
                }
              })
            }
          }
          this.loading = false
        }).catch(() => {
          this.loading = false
        })
      } else {
        if (this.mainId) {
          getDfgzDealOtherInfoByMainId(this.mainId).then(response => {
            if (response.data) {
              this.form = response.data
            } else {
              this.reset()
              if (this.$route.query.companyId) {
                getCompanyBase(this.$route.query.companyId).then(res => {
                  if (res.data) {
                    this.form.actualBusinessLocation = res.data.detailsRegistered
                  }
                })
              }
            }
            this.loading = false
          }).catch(() => {
            this.loading = false
          })
        } else {
          this.reset()
          this.loading = false
        }
      }
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        mainId: this.$route.query.dealId ? this.$route.query.companyId : this.$route.query.id,
        listingSituation: undefined,
        corporateHonors: undefined,
        isNewThirdBoardEnterprises: 'N',
        newThirdBoardCode: undefined,
        isMinorEnterprises: 'N',
        isUnicornEnterprise: 'N',
        isGazelleEnterprise: 'N',
        isInnovativeEnterprises: 'N',
        duration: undefined,
        actualBusinessLocation: undefined,
        otherHighlights: undefined,
        exitPattern: undefined,
        delegationSituation: undefined,
        isManagementCompany: 'N',
        organizationalForm: undefined,
        participationMethod: undefined,
        promoter: undefined,
        gpTeamCoreMembers: undefined,
        remark: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined
      }
      this.resetForm('form')
    },
    // 取消按钮
    cancel() {
      this.$parent.$parent.formOpen = false
      this.$parent.$parent.reset()
    },
    // 关闭form页面
    closeForm() {
      // 关闭form页面遮罩层
      this.loading = false
      // 关闭form页面
      if (this.$parent.$parent.formOpen !== undefined) {
        this.$parent.$parent.formOpen = false
      }
      // 刷新list页面
      if (this.$parent.$parent.getList !== undefined) {
        this.$parent.$parent.getList()
      }
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.loading = true
          saveDfgzDealOtherInfo(this.form).then(response => {
            if (response.code === 200) {
              this.msgSuccess(this.$t('保存成功'))
              this.loading = false
            } else {
              this.msgError(response.msg)
            }
            this.loading = false
          })
        } else {
          this.locationError(document)
        }
      }).catch(() => {
        this.loading = false
      })
    }
  }
}
</script>
